// pages/activity/list/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
      list:[],
      pagination:{},
      query:{},
      currentPage:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const that = this
    that.getActivityList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
 
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    const that = this
    that.getActivityList()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  onShareTimeline(){

  },
  getActivityList() {
    const that = this
    that.data.query.page = that.data.currentPage + 1;
    app.api.get(app.getUrl('activity'), that.data.query).then((res)=>{
      if(res.data.length>0) {
        that.setData({
          list:res.data,
          currentPage:res.pagination.current
        })
      }

    })
  },
  //下拉刷新
  refreshActivityList() {
    const that = this
    console.log('refresh')
    setTimeout(function() {
      that.setData({
        refreshStatus:true
      })
    }, 1000)
  },//活动详情
  ActivityDetail(e) {
    let id = e.currentTarget.dataset.id;
    console.log(id)
    wx.navigateTo({
      url: '/pages/activity/detail/index?id='+id,
    })
  }
})